package cn.ld.module.system.dal.mapper.permission;

import cn.ld.framework.mybatis.core.mapper.BaseMapperX;
import cn.ld.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.ld.module.system.controller.admin.permission.vo.menu.MenuListInVO;
import cn.ld.module.system.dal.entity.permission.MenuEntity;
import org.apache.ibatis.annotations.Mapper;

import java.util.List;

@Mapper
public interface MenuMapper extends BaseMapperX<MenuEntity> {

    default MenuEntity selectByParentIdAndName(Long parentId, String name) {
        return selectOne(MenuEntity::getParentId, parentId, MenuEntity::getName, name);
    }

    default Long selectCountByParentId(Long parentId) {
        return selectCount(MenuEntity::getParentId, parentId);
    }

    default List<MenuEntity> selectList(MenuListInVO inVO) {
        return selectList(new LambdaQueryWrapperX<MenuEntity>()
                .likeIfPresent(MenuEntity::getName, inVO.getName())
                .eqIfPresent(MenuEntity::getStatus, inVO.getStatus()));
    }

    default List<MenuEntity> selectListByPermission(String permission) {
        return selectList(MenuEntity::getPermission, permission);
    }
}
